# This script create a folder named 'v' under base_path, and then create folders for each person to put all corresponding videos in.
import os
import shutil
data_path='D:/Datasets/ytcelebrity/'
dataset_path = 'D:/Datasets/ytcelebrity/v/'
fileList = os.listdir(data_path)
i=0
for file in fileList:
    old_path=os.path.join(data_path,file)
    l=list(file.split('_'))
    file_name=l[-2]+'_'+l[-1]
    file_name = file_name.rstrip(".avi")
    file_path=os.path.join(data_path,file_name)
    # if file_path not in list1:
    #     list1.append(file_path)
    if not os.path.exists(file_path):
        os.mkdir(file_path)
    shutil.move(old_path,file_path)
    i+=1
    print(i)

os.mkdir(dataset_path)
fileList = os.listdir(data_path)
for file in fileList:
	if file != 'v':
		old_path=os.path.join(data_path,file)
		shutil.move(old_path,dataset_path + file)
